{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use Case 11\n",
    "===========\n",
    "\n",
    "Problem Definition:\n",
    "-------------------\n",
    "\n",
    "As part of a project on Arctic climate change, an undergraduate student wishes to look\n",
    "at different ECVs on a polar stereographic projection.\n",
    "\n",
    "Required Toolbox Features:\n",
    "--------------------------\n",
    "\n",
    "* Access to and ingestion of CCI ECV data (e.g. sea ice, ice sheets, sea level, SST, clouds aerosol)\n",
    "* Access to and ingestion of ECV data from external server\n",
    "* Remapping to fit data onto user-chosen projection\n",
    "* Spatial and temporal subsetting\n",
    "* Gap-filling (user-chosen strategy)\n",
    "* Generation of scalable maps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# To reduce bandwith, spatial and temporal subsetting is done when downloading the dataset\n",
    "from cate import ops\n",
    "from cate.util.monitor import ConsoleMonitor\n",
    "\n",
    "monitor = ConsoleMonitor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sst_polar = ops.open_dataset(ds_id='esacci.SST.day.L4.SSTdepth.multi-sensor.multi-platform.OSTIA.1-1.r1',\n",
    "                             region=(-180, 60, 180, 90),\n",
    "                             time_range='2007-01-01, 2007-01-15',\n",
    "                             var_names='analysed_sst, sea_ice_fraction',\n",
    "                             force_local=True,\n",
    "                             local_ds_id='SST_polar_2007',\n",
    "                             normalize=False,\n",
    "                             monitor=monitor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Above creates the dataset, but errors out when trying to open it\n",
    "sst_polar = ops.open_dataset('local.SST_polar_2007')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "ops.plot_map(sst_polar, var='sea_ice_fraction', region=(-180, 60, 180, 90), projection='NorthPolarStereo',\n",
    "             contour_plot=True, file='sst.svg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cld_polar = ops.open_dataset(ds_id='esacci.CLOUD.mon.L3C.CLD_PRODUCTS.AVHRR.multi-platform.AVHRR-AM.2-0.r1',\n",
    "                             region=(-180, 60, 180, 90),\n",
    "                             time_range='2007-01-01, 2007-01-31',\n",
    "                             var_names='cfc, cee',\n",
    "                             force_local=True,\n",
    "                             local_ds_id='CLOUDS_polar_2007',\n",
    "                             normalize=False,\n",
    "                             monitor=monitor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "clouds = ops.open_dataset('local.CLOUDS_polar_2007')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ops.plot_map(clouds, var='cfc', region=(-180, 60, 180, 90), projection='NorthPolarStereo', file='polar_clouds.svg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "aerosol_polar = ops.open_dataset(ds_id='esacci.AEROSOL.mon.L3.AAI.multi-sensor.multi-platform.ms_uvai.1-5-7.r1',\n",
    "                                 region=(-180, 60, 180, 90),\n",
    "                                 time_range='2007-01-01, 2007-03-31',\n",
    "                                 force_local=True,\n",
    "                                 local_ds_id='AEROSOL_polar_2007',\n",
    "                                 monitor=monitor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "aerosol = ops.open_dataset('local.AEROSOL_polar_2007')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ops.plot_map(aerosol, region=(-180, 60, 180, 90), var='absorbing_aerosol_index', projection='NorthPolarStereo',\n",
    "             file='aerosol_polar.svg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
